(计算机科学/并发编程)临界区/关键区域:在多线程或多进程中,访问共享资源(如共享变量、文件、缓冲区)的那段代码或操作范围;为避免数据错误,通常需要保证同一时刻只有一个执行单元进入。常见近义术语是 critical section(临界区)。
/ˈkrɪtɪkəl ˈriːdʒən/
The lock prevents two threads from entering the critical region at the same time.
锁可以防止两个线程同时进入临界区。
To ensure correctness under high concurrency, the program guards every critical region that updates shared state with a mutex and carefully defines the boundaries of that region.
为在高并发下保证正确性,程序用互斥锁保护每个会更新共享状态的临界区,并谨慎界定该区域的边界。
critical 源自希腊语 kritikos(“能判断的、关键的”),经拉丁语与法语进入英语,常引申为“决定成败的、需要谨慎处理的”。region 来自拉丁语 regio(“区域、范围”)。合在一起的 critical region 强调“对结果至关重要、必须被妥善控制的那一段区域/范围”,在并发语境中特指需要互斥访问的代码区域。